package com.lzw.service.impl.admin;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lzw.mapper.admin.AnnouncementMapper;
import com.lzw.pojo.Announcement;
import com.lzw.service.admin.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class AnnouncementImpl implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public List<Announcement> listAnnouncement(Integer pageNum, Integer pageSize, LocalDate datePosted, String postedBy) {
        PageHelper.startPage(pageNum,pageSize);
        List<Announcement> list = announcementMapper.listAnnouncement(datePosted, postedBy);
        Page<Announcement> announcements = (Page<Announcement>) list;
        return announcements;
    }

    @Override
    public void addAnnouncement(Announcement announcement) {
        announcement.setDatePosted(LocalDate.now());
        announcementMapper.addAnnouncement(announcement);
    }

    @Override
    public void deleteAnnouncement(List<Integer> ids) {
        announcementMapper.deleteAnnouncement(ids);
    }

    @Override
    public Announcement getAnnouncementById(int id) {
        return announcementMapper.getAnnouncementById(id);
    }

    @Override
    public void updateAnnouncement(Announcement announcement) {
        announcement.setDatePosted(LocalDate.now());
        announcementMapper.updateAnnouncement(announcement);
    }
}
